/* created at 2008-07-05:00:17:59 */
package pl.kwiecienm.jcomet.calculations;

import java.util.Collection;

import pl.kwiecienm.jcomet.Calculation;
import pl.kwiecienm.jcomet.model.AnalysisResult;

/**
 * Compares Comparables.
 * 
 * @author kwiecienm
 */
public class Max implements Calculation {

    /** */
    public static final String CALCULATION_MAX = "calculation.max";

    /** */
    private String             _calculationParameter;

    /** */
    private String             _name;

    /** */
    @SuppressWarnings("unchecked")
    @Override
    public AnalysisResult calculate(Collection<AnalysisResult> inData) {
        AnalysisResult ret = new AnalysisResult();

        Comparable max = null;
        for (AnalysisResult result : inData) {
            if (max == null) {
                max = (Comparable) result.get(this._calculationParameter);
            }
            Comparable temp = (Comparable) result
                    .get(this._calculationParameter);
            if (max.compareTo(temp) < 0) {
                max = temp;
            }
        }

        ret.put(CALCULATION_MAX, max);
        ret.put(AnalysisResult.CHILDREN, inData);

        return ret;
    }

    /**
     * @return the calculationParameter
     */
    public String getCalculationParameter() {
        return this._calculationParameter;
    }

    /**
     * @param inCalculationParameter the calculationParameter to set
     */
    public void setCalculationParameter(String inCalculationParameter) {
        this._calculationParameter = inCalculationParameter;
    }

    /**
     * @return the name
     */
    public String getName() {
        return this._name;
    }

    /**
     * @param inName the name to set
     */
    public void setName(String inName) {
        this._name = inName;
    }
}
